/* 数据一张图调接口文件
 * @ 劳兆城
 * @ 2017-08-08 */

import store from 'src/store'
import axios from 'axios'
import { ajaxPost, ajaxGet } from './axios'
import { httpUrl, options, mapHttpUrl20462 } from './config'
import { getWantObject } from 'common/js/util'

// 台风路径列表
export function getTyphoonList () {
	let url = `${httpUrl}fullservice/http/typhoonInfo`

	let data = {}

	return ajaxGet(url, data)
}

// 单个台风路径信息
export function getTyphoonSingelInfo (tfbh) {
	let url = `${httpUrl}fullservice/http/typhoonPath`

	let data = {
		tfbh
	}

	return ajaxGet(url, data)
}

// 水库信息
export function getReservoirInfo (num) {
	let url = `${httpUrl}fullservice/http/reservoirMajor10`

	let data = {
		stn_no: num
	}
	return ajaxGet(url, data)
}

// 水闸、泵站信息
export function getGateInfo (num) {
	let url = `${httpUrl}fullservice/http/waterDataReal`

	let data = {
		stn_no: num
	}
	return ajaxGet(url, data)
}

// 内涝点、水位站、潮位站信息
export function getWaterloggingInfo (num) {
	let url = `${httpUrl}fullservice/http/waterlevelDataReal`

	let data = {
		stn_no: num
	}
	return ajaxGet(url, data)
}

// 土壤湿度
export function getSoilMoistureInfo () {
	let url = `${httpUrl}fullservice/http/landwater`

	let data = {}

	return ajaxGet(url, data)
}

// 根据 经纬度 获取 河的信息
export function getSingleWaterNet (lat, lng) {
	let url = `${mapHttpUrl20462}arcgis/rest/services/data_visualization/guangdong_waterbody_entire/MapServer/identify`

	let data = {
		geometry: `(${lat},${lng})`,
		tolerance: 10,
		geometryType: 'esriGeometryPoint',
		sr: '',
		layers: '',
		layerDefs: '',
		time: '',
		layerTimeOptions: '',
		mapExtent: '111,20,114,26',
		imageDisplay: 'imageDisplay=600,550,96',
		returnGeometry: 'true',
		maxAllowableOffset: '',
		geometryPrecision: '',
		dynamicLayers: '',
		returnZ: 'false',
		returnM: 'false',
		gdbVersion: '',
		f: 'pjson'
	}
	return ajaxGet(url, data)
}

// 内河涌-基本信息-查询
export function getWaterNetInfo (page = 1, searchValue = {}) {
	let url = 'sanfang_river/onepicture/ztwaterstriv/list'

	let data = {
		page: page,
		pageSize: 10,
		searchValue: searchValue
	}

	return ajaxPost(url, data, options)
}

// 内河涌-基本信息-保存
export function editWaterNetInfo (data) {
	let url = 'sanfang_river/onepicture/ztwaterstriv/edit'

	return ajaxPost(url, data, options)
}

// 内河涌-桩端信息-查询
export function getWaterPile (page = 1) {
	let url = 'sanfang_river/onepicture/ztwaterstrivseg/list'

	let data = {
		page: page,
		pageSize: 10,
		searchValue: {
			strivid: store.getters.singleWaterNetId
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-桩端信息-新增
export function addWaterPile () {
	let url = 'sanfang_river/onepicture/ztwaterstrivseg/new'

	let data = {
		segcode: '',
		segname: '',
		segorder: '',
		lfttop: '',
		lftedge: '',
		lftbake: '',
		rghtop: '',
		rghedge: '',
		rghbake: '',
		btmwidth: '',
		brokenwidth: '',
		strivid: store.getters.singleWaterNetId
	}

	return ajaxPost(url, data, options)
}

// 内河涌-桩端信息-保存
export function editWaterPile (data) {
	let url = 'sanfang_river/onepicture/ztwaterstrivseg/edit'

	return ajaxPost(url, data, options)
}

// 内河涌-桩端信息-删除
export function delWaterPile (id) {
	let url = 'sanfang_river/onepicture/ztwaterstrivseg/delete'

	let data = {
		strivsegid: id
	}

	return ajaxPost(url, data, options)
}

// 内河涌-河涌景观-查询
export function getWaterProfile (page = 1) {
	let url = 'sanfang_river/onepicture/ztwaterstrivpic/list'

	let data = {
		page: page,
		pageSize: 10,
		searchValue: {
			strivid: store.getters.singleWaterNetId
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-河涌景观-删除
export function delWaterProfile (id) {
	let url = 'sanfang_river/onepicture/ztwaterstrivseg/delete'

	let data = {
		strivpicid: id
	}

	return ajaxPost(url, data, options)
}

// 内河涌-排水口信息-查询
export function getWaterOutfall (page = 1) {
	let url = 'sanfang_river/onepicture/ztwaterstrivkeypnt/list'

	let data = {
		page: page,
		pageSize: 10,
		searchValue: {
			strivid: store.getters.singleWaterNetId
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-排水口信息-新增
export function addWaterOutfall () {
	let url = 'sanfang_river/onepicture/ztwaterstrivkeypnt/new'

	let data = {
		pntcode: '',
		pntdir: '',
		trntype: '',
		trnsource: '',
		trnsieze: '',
		trnheight: '',
		pntplace: '',
		trntonnage: '',
		trnhandleway: '',
		trnhandleyear: '',
		builddate: '',
		buildman: '',
		coldate: '',
		colman: '',
		pntcomment: '',
		zoomimgpath: '',
		strivid: store.getters.singleWaterNetId
	}

	return ajaxPost(url, data, options)
}

// 内河涌-排水口信息-保存
export function editWaterOutfall (data) {
	let url = 'sanfang_river/onepicture/ztwaterstrivkeypnt/edit'

	return ajaxPost(url, data, options)
}

// 内河涌-排水口信息-删除
export function delWaterOutfall (id) {
	let url = 'sanfang_river/onepicture/ztwaterstrivkeypnt/delete'

	let data = {
		strivkeypntid: id
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况-查询
export function getWaterQuality (page = 1) {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterpnt/list'

	let data = {
		page: page,
		pageSize: 10,
		searchValue: {
			strivid: store.getters.singleWaterNetId
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况-新增
export function addWaterQuality () {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterpnt/new'

	let data = {
		pntcode: '',
		pntdir: '',
		trntype: '',
		trnsource: '',
		trnsieze: '',
		trnheight: '',
		pntplace: '',
		trntonnage: '',
		trnhandleway: '',
		trnhandleyear: '',
		builddate: '',
		buildman: '',
		coldate: '',
		colman: '',
		pntcomment: '',
		zoomimgpath: '',
		strivid: store.getters.singleWaterNetId
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况-保存
export function editWaterQuality (data) {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterpnt/edit'

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况-删除
export function delWaterQuality (id) {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterpnt/delete'

	let data = {
		wtwaterpntid: id
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况图例-查询
export function getWaterQualityLegend (id = '') {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterresult/list'

	let data = {
		page: 1,
		pageSize: 1000,
		searchValue: {
			strivid: store.getters.singleWaterNetId,
			wtwaterpntid: id
		},
		order: {
			pntorder: 1,
			showorder: 1
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况图例-新增
export function addWaterQualityLegend (id = '') {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterresult/new'

	let data = {
		local: '',
		ph: '',
		suspended: '',
		chemistry: '',
		biology: '',
		ammonia: '',
		total: '',
		other: '',
		wtwaterpntid: id,
		strivid: store.getters.singleWaterNetId
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况图例-保存
export function editWaterQualityLegend (obj = {}) {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterresult/edit'

	let arr = ['id', 'index', 'leftvalue', 'pntorder', 'pntplace', 'rightvalue', 'showorder', 'strivid', 'stwatertempid', 'waterkey', 'wtwaterpntid', 'wtwaterresultid']

	let data = getWantObject(arr, obj)

	return ajaxPost(url, data, options)
}

// 内河涌-水质情况图例-删除
export function delWaterQualityLegend (arr = []) {
	let url = 'sanfang_river/onepicture/ztwaterwtwaterresult/delete'

	let data = {
		ids: arr.join(',')
	}

	return ajaxPost(url, data, options)
}

// 内河涌-水质趋势图-查询
export function getWaterPicture () {
	let url = 'sanfang_river/onepicture/ztwaterresultgraph/list'

	let data = {
		strivid: store.getters.singleWaterNetId
	}

	return ajaxPost(url, data, options)
}

// 内河涌-整治方案-信息-查询
export function getWaterRenovationInfo () {
	let url = 'sanfang_river/onepicture/ztwaterstrivext/list'

	let data = {
		page: 1,
		pageSize: 1000,
		searchValue: {
			strivid: store.getters.singleWaterNetId
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-整治方案-信息-保存
export function editWaterRenovationInfo (data) {
	let url = 'sanfang_river/onepicture/ztwaterstrivext/edit'

	return ajaxPost(url, data, options)
}

// 内河涌-整治方案-表格选择-查询
export function getWaterRenovationTable () {
	let url = 'sanfang_river/onepicture/ztwatersthandletemp/list'

	let data = {
		page: 1,
		pageSize: 1000,
		searchValue: {}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-整治方案-表格已选择-查询
export function getWaterRenovationChosed () {
	let url = 'sanfang_river/onepicture/ztwaterstrivhandle/list'

	let data = {
		page: 1,
		pageSize: 1000,
		searchValue: {
			strivid: store.getters.singleWaterNetId
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-整治方案-表格已选择-保存
export function editWaterRenovationChosed (arr) {
	let url = 'sanfang_river/onepicture/ztwaterstrivhandle/edit'

	let data = {
		strivid: store.getters.singleWaterNetId,
		key: arr
	}

	return ajaxPost(url, data, options)
}

// 内河涌-建筑物信息-查询
export function getWaterBuild (page = 1, obj = {}) {
	let url = 'sanfang_river/onepicture/riverbuilding/list'

	let data = {
		page: page,
		pageSize: 9,
		searchValue: {
			strivid: store.getters.singleWaterNetId,
			...obj
		}
	}

	return ajaxPost(url, data, options)
}

// 内河涌-建筑物信息-删除
export function delWaterBuild (id) {
	let url = 'sanfang_river/onepicture/riverbuilding/delete'

	let data = {
		buildid: id
	}

	return ajaxPost(url, data, options)
}

// 堤围信息
export function getBanksInfo (name) {
	let data = {
		name: name
	}

	let obj = {
		sizeInfo () {
			return axios.get(`${httpUrl}fullservice/http/dikeInfo`, {
				params: data
			})
		},
		dangerouInfo () {
			return axios.get(`${httpUrl}fullservice/http/dikeDangerousInfo`, {
				params: data
			})
		}
	}

	let arr = [obj.sizeInfo(), obj.dangerouInfo()]

	return axios.all(arr).then(axios.spread((size, danger) => {
		return Promise.resolve({
			size: size.data,
			danger: danger.data
		})
	}))
}

// 险段信息
export function getCriticalsInfo (name) {
	let url = `${httpUrl}fullservice/http/dikeDangerousInfo`

	let data = {
		name: name
	}

	return ajaxGet(url, data)
}
